import { request } from "./request";
//登录
export function postLogin(loginForm) {
  return request({
    method: "post",
    url: "/user",
    // //data对应post请求
    data: {
      username: loginForm.username,
      password: loginForm.password
    }
    // //params对应get请求
    // params: {
    //   username: loginForm.username,
    //   password: loginForm.password,
    // },
  });
}
//查询用户列表
export function getUserList(queryInfo) {
  return request({
    method: "get",
    url: "/user",
    params: queryInfo //参数为类型为object,不用加花括号进行参数指定
  });
}
// 更新单个用户
export function patchUser(id, patchDocument) {
  return request({
    method: "patch",
    url: `/user/${id}`,
    data: patchDocument //参数为类型为object,不用加花括号进行参数指定
  });
}
// 添加用户
export function addUser(addUserInfo) {
  return request({
    method: "post",
    url: "/user/addUser",
    data: addUserInfo
  });
}
//查询单个用户信息
export function getUserInfo(id) {
  return request({
    method: "get",
    url: `/user/${id}`
  });
}
// 更新用户信息
export function putUserInfo(userInfo) {
  return request({
    method: "put",
    url: "/user",
    data: userInfo
  });
}
//删除用户信息
export function deleteUser(id) {
  return request({
    method: "delete",
    url: `/user/${id}`
    //data:{}
  });
}
//为用户分配角色
export function allotUserRole(userId, idStr) {
  // axios默认对请求体序列化,后端拿不到string类型的参数, 需要用对象接收
  //通过URLSearchParams可以使请求Content-type变成"application/x-www-form-urlencoded",后端可以在Request.Form
  const params = new URLSearchParams();
  params.append("ids", idStr);
  return request({
    method: "post",
    url: `/user/${userId}/role/`,
    data: params
  });
}
